#include "calculate_lowercomputer_data.h"
#include "global_variant.h"

#include <cmath>
#include <QDebug>

// CalculateLowerComputerData::CalculateLowerComputerData(QObject *parent)
//     : QObject{parent}
CalculateLowerComputerData::CalculateLowerComputerData()
{
    //启动定时器：用于发送心跳
    m_timer = new QTimer(this);

    //连接定时器的信号与槽，定时时间一到就会发送 timeout() 信号，从而触发槽函数dealHeartBeat（处理心跳）
    connect(m_timer, &QTimer::timeout,
            this, [&](){
                /**
大闸制动，小闸缓解，制动压力不变
小闸制动，只有大闸的下压可以减少制动压力
紧急制动，只有紧急制动缓
辅助制动，只有辅助制动可以缓解
总风缸压力降到660一下，会自动冲压到720
**/
                //qDebug()<<"CalculateLowerComputerData";
                if(g_startDieselEngine == true && m_totalWindCylinderPressure < 720.0 && m_isImpulsetotalWindCylinderPressure){//开启发动机
                    //只冲总风缸压力，压力不足660时，再重新冲到720
                    //列车管、均风缸、制动缸的压力，均不能大于总风杠
                    if(m_totalWindCylinderPressure + m_totalWindCylinderPressureAcceleration_1 +  abs((static_cast<double>(g_throttleFactorFront/100.0) * 3.0)) * m_totalWindCylinderPressureAcceleration_1 < 720.0){
                        m_totalWindCylinderPressure += m_totalWindCylinderPressureAcceleration_1 + abs((static_cast<double>(g_throttleFactorFront/100.0) * 3.0)) * m_totalWindCylinderPressureAcceleration_1;
                    }else{
                        m_totalWindCylinderPressure = 720.0;
                        m_isImpulsetotalWindCylinderPressure = false;
                    }

                }

                if(g_startDieselEngine == false){
                    if(m_totalWindCylinderPressure - m_totalWindCylinderPressureAcceleration_1 - abs((static_cast<double>(g_throttleFactorFront/100.0) * 3.0)) * m_totalWindCylinderPressureAcceleration_1 > 0.0){
                        m_totalWindCylinderPressure = m_totalWindCylinderPressure - m_totalWindCylinderPressureAcceleration_1 - abs((static_cast<double>(g_throttleFactorFront/100.0) * 3.0)) * m_totalWindCylinderPressureAcceleration_1;
                    }else{
                        m_totalWindCylinderPressure = 0.0;
                    }


                    // qDebug()<<"m_totalWindCylinderPressure:"<<m_totalWindCylinderPressure;
                }

                //辅助制动压力为0
                if(m_auxiliaryBrakingBrakeCylinderPressure <= 0.0){
                    //大闸保压位/运转位
                    //释放列车管和制动缸压力
                    if((g_bigGateType == BigSmallGate::PreservationPressureLocationType
                         || g_bigGateType == BigSmallGate::OperatingPositionType)
                        && (m_emergencyBrakingBrakeCylinderPressure > 0.0
                            || m_bigGateBrakeCylinderPressure > 0.0)){
                        if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0
                            && (m_emergencyBrakingBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0
                                || m_bigGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0)){
                            m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_9;

                            if(m_emergencyBrakingBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0){
                                m_emergencyBrakingBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_9;

                            }else if(m_bigGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0){
                                m_bigGateBrakeCylinderPressure -=  m_brakeCylinderPressureAcceleration_9;

                            }
                        }else{
                            m_brakeCylinderPressure = 0.0;

                            m_bigGateBrakeCylinderPressure = 0.0;
                            m_emergencyBrakingBrakeCylinderPressure = 0.0;
                        }

                        if(m_trainPipePressure - m_trainPipePressureAcceleration_9 > 0.0){
                            m_trainPipePressure -= m_trainPipePressureAcceleration_9;
                        }else{
                            m_trainPipePressure = 0.0;
                        }


                        qDebug()<<"大闸保压/运转位";
                        qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                        qDebug()<<"m_trainPipePressure:"<< m_trainPipePressure;
                        qDebug()<<"m_emergencyBrakingBrakeCylinderPressure:"<<m_emergencyBrakingBrakeCylinderPressure;
                        qDebug()<<"m_bigGateBrakeCylinderPressure:"<<m_bigGateBrakeCylinderPressure;

                    }

                    //小闸运转位和保压位
                    if((g_smallGateType == BigSmallGate::PreservationPressureLocationType
                         || g_smallGateType == BigSmallGate::OperatingPositionType)
                        && m_smallGateBrakeCylinderPressure > 0.0
                        && m_bigGateBrakeCylinderPressure <= 0.0
                        && m_emergencyBrakingBrakeCylinderPressure <= 0.0){
                        if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_9 > 0.0){
                            m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_9;

                            // m_smallGateBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_9;

                        }else{
                            m_brakeCylinderPressure = 0.0;

                            // m_smallGateBrakeCylinderPressure = 0.0;
                        }
                        // m_smallGateBrakeCylinderPressureMinChangeValue = m_smallGateBrakeCylinderPressure;

                        qDebug()<<"小闸缓解/保压";
                        qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                        qDebug()<<"m_smallGateBrakeCylinderPressure:"<<m_smallGateBrakeCylinderPressure;
                    }

                }

                //大闸(列车管，均衡风杠)
                if(g_bigGateType == BigSmallGate::ReliefPositionType){//缓解位（列车管、均衡风杠）
                    if( m_trainPipePressure + m_trainPipePressureAcceleration_10 < 500.0){
                        m_trainPipePressure += m_trainPipePressureAcceleration_10;

                        m_totalWindCylinderPressure -= m_trainPipePressureAcceleration_10/50;
                    }else{
                        m_trainPipePressure = 500.0;
                    }

                    if(m_trainPipePressure > m_totalWindCylinderPressure){
                        m_trainPipePressure = m_totalWindCylinderPressure;
                    }else{

                    }


                    if( m_equalizeCylinderPressure + m_equalizeCylinderPressureAcceleration_10 < 250.0){
                        m_equalizeCylinderPressure += m_equalizeCylinderPressureAcceleration_10;

                        m_totalWindCylinderPressure -= m_equalizeCylinderPressureAcceleration_10/50;
                    }else if( m_equalizeCylinderPressure + m_equalizeCylinderPressureAcceleration_11 < 500.0){
                        m_equalizeCylinderPressure += m_equalizeCylinderPressureAcceleration_11;

                        m_totalWindCylinderPressure -= m_equalizeCylinderPressureAcceleration_11/50;
                    }
                    else{
                        m_equalizeCylinderPressure = 500.0;
                    }

                    if(m_equalizeCylinderPressure > m_totalWindCylinderPressure){
                        m_equalizeCylinderPressure = m_totalWindCylinderPressure;
                    }else{

                    }
                }

                if(g_emergencyBraking){//紧急制动
                    m_maxBrakeCylinderPressure = 430.0;

                    if(m_trainPipePressure - m_trainPipePressureAcceleration_6 > 0.0){//够减才减
                        m_trainPipePressure -= m_trainPipePressureAcceleration_6;
                    }else{
                        m_trainPipePressure = 0.0;
                    }

                    if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_6 < 400.0 && m_totalWindCylinderPressure - m_brakeCylinderPressureAcceleration_6/5 > m_brakeCylinderPressure){
                        m_totalWindCylinderPressure -= m_brakeCylinderPressureAcceleration_6/5;
                    }

                    if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_6 < 400.0){
                        m_brakeCylinderPressure += m_brakeCylinderPressureAcceleration_6;

                        m_emergencyBrakingBrakeCylinderPressure += m_brakeCylinderPressureAcceleration_6;

                    }else if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_8 < 430.0){
                        m_brakeCylinderPressure += m_brakeCylinderPressureAcceleration_8;

                        m_emergencyBrakingBrakeCylinderPressure += m_brakeCylinderPressureAcceleration_8;


                        // g_isEmergencyBrakingBrakeCylinderPressureDivulge = true;
                    }else{
                        if(g_brakeCylinderPressure != m_maxBrakeCylinderPressure){
                            m_emergencyBrakingBrakeCylinderPressure += (430.0 - m_brakeCylinderPressure);
                        }

                        m_brakeCylinderPressure = 430.0;
                    }

                    m_emergencyBrakingBrakeCylinderPressureSaveChangeValue = m_emergencyBrakingBrakeCylinderPressure;


                    if(m_brakeCylinderPressure > m_totalWindCylinderPressure){
                        m_brakeCylinderPressure = m_totalWindCylinderPressure;
                    }

                    if(m_brakeCylinderPressure > 360.0){
                        m_maxBrakeCylinderPressure = 430.0;

                        m_maxBrakeCylinderPressureSaveMax = m_brakeCylinderPressure;
                    }

                    //紧急制动【大闸缓解】,会泄露总风缸压力
                    if(g_bigGateType == BigSmallGate::ReliefPositionType
                        || g_bigGateType == BigSmallGate::OperatingPositionType){

                        if(m_totalWindCylinderPressureDecreasevalue < 25.0){
                            if(m_totalWindCylinderPressure - m_totalWindCylinderPressureAcceleration_1*5 > 0.0){//够减才减
                                m_totalWindCylinderPressure -= m_totalWindCylinderPressureAcceleration_1*5;
                                m_totalWindCylinderPressureDecreasevalue += m_totalWindCylinderPressureAcceleration_1;
                            }else{
                                m_totalWindCylinderPressure = 0.0;
                            }
                        }else{
                            if(m_totalWindCylinderPressure - m_trainPipePressureAcceleration_6 > 0.0){//够减才减
                                m_totalWindCylinderPressure -= m_trainPipePressureAcceleration_6;
                            }else{
                                m_totalWindCylinderPressure = 0.0;
                                m_totalWindCylinderPressureDecreasevalue = 0.0;
                            }
                        }
                    }

                    m_maxBrakeCylinderPressureSaveMax = m_brakeCylinderPressure;

                    qDebug()<<"紧急制动";
                    qDebug()<<"g_brakeCylinderPressure:"<<g_brakeCylinderPressure;
                    qDebug()<<"m_maxBrakeCylinderPressure:"<<m_maxBrakeCylinderPressure;
                    qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                    qDebug()<<"m_emergencyBrakingBrakeCylinderPressure:"<<m_emergencyBrakingBrakeCylinderPressure;
                    qDebug()<<"m_emergencyBrakingBrakeCylinderPressureSaveChangeValue:"<<m_emergencyBrakingBrakeCylinderPressureSaveChangeValue;
                    qDebug()<<"m_maxBrakeCylinderPressureSaveMax:"<<m_maxBrakeCylinderPressureSaveMax;

                }else{
                    //辅助制动
                    if(g_auxiliaryBraking == true){
                        //使用总风缸压力
                        if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_7  < 360.0 && m_totalWindCylinderPressure - m_brakeCylinderPressureAcceleration_7/5 > m_brakeCylinderPressure){
                            m_totalWindCylinderPressure -= m_brakeCylinderPressureAcceleration_7/5;
                        }

                        //制动压力
                        if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_7  < 360.0 && m_brakeCylinderPressure  <= m_totalWindCylinderPressure){
                            m_brakeCylinderPressure += m_brakeCylinderPressureAcceleration_7;
                            m_auxiliaryBrakingBrakeCylinderPressure += m_brakeCylinderPressureAcceleration_7;
                        }else{
                            m_auxiliaryBrakingBrakeCylinderPressure += (360.0 - m_brakeCylinderPressure);

                            m_brakeCylinderPressure = 360.0;

                        }

                        m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue = m_auxiliaryBrakingBrakeCylinderPressure;

                        if(m_brakeCylinderPressure >m_totalWindCylinderPressure){
                            m_brakeCylinderPressure = m_totalWindCylinderPressure;
                        }else{

                        }

                        m_maxBrakeCylinderPressureSaveMax = m_brakeCylinderPressure;

                        qDebug()<<"辅助制动开启:";
                        qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                        qDebug()<<"m_auxiliaryBrakingBrakeCylinderPressure:"<<m_auxiliaryBrakingBrakeCylinderPressure;
                        qDebug()<<"m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue:"<<m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue;
                        qDebug()<<"m_totalWindCylinderPressure:"<<m_totalWindCylinderPressure;
                        qDebug()<<"m_maxBrakeCylinderPressureSaveMax:"<<m_maxBrakeCylinderPressureSaveMax;

                    }else{
                        //先把辅助制动压力排空，再做其他操作
                        if(m_auxiliaryBrakingBrakeCylinderPressure > 0.0){
                            if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_7  > 0.0
                                && m_auxiliaryBrakingBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_7 > 0.0){

                                m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_7;
                                m_auxiliaryBrakingBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_7;
                            }else{
                                if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_7  > 0.0){//还有其他制动压力
                                    m_brakeCylinderPressure = m_maxBrakeCylinderPressureSaveMax -  m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue;
                                }else{
                                    m_brakeCylinderPressure = 0.0;
                                    m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue = 0.0;
                                }
                                m_auxiliaryBrakingBrakeCylinderPressure = 0.0;
                            }

                            qDebug()<<"辅助制动关闭:";
                            qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                            qDebug()<<"m_auxiliaryBrakingBrakeCylinderPressure:"<<m_auxiliaryBrakingBrakeCylinderPressure;
                            qDebug()<<"m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue:"<<m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue;
                        }else{
                            //大闸【缓解位】
                            if(g_bigGateType == BigSmallGate::ReliefPositionType &&
                                (m_bigGateBrakeCylinderPressure > 0.0
                                 ||m_emergencyBrakingBrakeCylinderPressure > 0.0)){//缓解位

                                if((m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_2 > 0.0)
                                    && (m_bigGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_2 > 0.0
                                        || m_emergencyBrakingBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_2  > 0.0)){

                                    m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_2;

                                    //先降低紧急制动，再降大闸制动
                                    if(m_emergencyBrakingBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_2 > 0.0){
                                        m_emergencyBrakingBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_2;
                                    }else if(m_bigGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_2 > 0.0){
                                        m_bigGateBrakeCylinderPressure -=  m_brakeCylinderPressureAcceleration_2;
                                    }
                                }else{

                                    if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_2 < 0.0){
                                        m_brakeCylinderPressure = 0.0;

                                    }else{//制动缸里还有小闸制动
                                    m_brakeCylinderPressure = m_maxBrakeCylinderPressureSaveMax
                                                              - m_bigGateBrakeCylinderPressureSaveChangeValue
                                                              - m_emergencyBrakingBrakeCylinderPressureSaveChangeValue
                                                              - m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue;

                                        m_bigGateBrakeCylinderPressureSaveChangeValue = 0.0;
                                        m_emergencyBrakingBrakeCylinderPressureSaveChangeValue = 0.0;
                                        m_maxBrakeCylinderPressureSaveMax = 0.0;
                                        m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue = 0.0;

                                    }

                                    m_bigGateBrakeCylinderPressure = 0.0;
                                    m_bigGateBrakeCylinderPressureSaveChangeValue = 0.0;

                                    m_emergencyBrakingBrakeCylinderPressure = 0.0;
                                    m_emergencyBrakingBrakeCylinderPressureSaveChangeValue = 0.0;

                                }

                                if(m_brakeCylinderPressure <= 360.0){
                                    m_maxBrakeCylinderPressure = 360.0;
                                }

                                qDebug()<<"大闸缓解";
                                qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                                qDebug()<<"m_bigGateBrakeCylinderPressure:"<<m_bigGateBrakeCylinderPressure;
                                qDebug()<<"m_bigGateBrakeCylinderPressureSaveChangeValue:"<<m_bigGateBrakeCylinderPressureSaveChangeValue;
                                qDebug()<<"m_emergencyBrakingBrakeCylinderPressure:"<<m_emergencyBrakingBrakeCylinderPressure;
                                qDebug()<<"m_emergencyBrakingBrakeCylinderPressureSaveChangeValue:"<<m_emergencyBrakingBrakeCylinderPressureSaveChangeValue;
                                qDebug()<<"m_maxBrakeCylinderPressureSaveMax:"<<m_maxBrakeCylinderPressureSaveMax;
                                qDebug()<<"m_maxBrakeCylinderPressure:"<<m_maxBrakeCylinderPressure;
                                qDebug()<<"m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue:"<<m_auxiliaryBrakingBrakeCylinderPressureSaveChangeValue;
                            }

                            //下压位(大闸)
                            //先缓解紧急制动的压力
                            if(g_bigGateType == BigSmallGate::PressDownType
                                && m_emergencyBrakingBrakeCylinderPressure <= 0.0){
                                if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_4  > 0.0){
                                    m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_4;

                                    //先缓解大闸制动，再缓解小闸制动
                                    if(m_bigGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_4 > 0.0){
                                        m_bigGateBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_4;

                                    }else if(m_smallGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_4 > 0.0){
                                        m_smallGateBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_4;


                                    }
                                }else{
                                    m_brakeCylinderPressure = 0.0;

                                    m_bigGateBrakeCylinderPressure = 0.0;

                                    m_smallGateBrakeCylinderPressure = 0.0;


                                }
                                qDebug()<<"大闸下压";
                                qDebug()<<"m_brakeCylinderPressure:"<<m_bigGateBrakeCylinderPressure;
                                qDebug()<<"m_bigGateBrakeCylinderPressure:"<<m_bigGateBrakeCylinderPressure;
                                qDebug()<<"m_smallGateBrakeCylinderPressure:"<<m_smallGateBrakeCylinderPressure;

                            }

                            //小闸【下压位、缓解位】
                            //先缓解了紧急制动、大闸制动，才能缓解小闸制动
                            if((g_smallGateType == BigSmallGate::PressDownType
                                 || g_smallGateType == BigSmallGate::ReliefPositionType)
                                && m_smallGateBrakeCylinderPressure > 0.0
                                && m_emergencyBrakingBrakeCylinderPressure <= 0.0
                                && m_bigGateBrakeCylinderPressure <= 0.0){//下压位、缓解位（小闸）

                                if(m_brakeCylinderPressure - m_brakeCylinderPressureAcceleration_5 >= 0.0
                                    && m_smallGateBrakeCylinderPressure - m_brakeCylinderPressureAcceleration_5 >= 0.0){
                                    m_brakeCylinderPressure -= m_brakeCylinderPressureAcceleration_5;

                                    m_smallGateBrakeCylinderPressure -= m_brakeCylinderPressureAcceleration_5;

                                }else{
                                    //不够减时，减为0；够减，则保持原址

                                    m_brakeCylinderPressure = 0.0;


                                    m_smallGateBrakeCylinderPressure = 0.0;

                                }

                                qDebug()<<"小闸缓解";
                                qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                                qDebug()<<"m_smallGateBrakeCylinderPressure："<<m_smallGateBrakeCylinderPressure;

                            }

                            //大闸【制动】
                            if(g_bigGateType == BigSmallGate::RetarderLocationType){
                                if(m_trainPipePressure - m_trainPipePressureAcceleration_2 > 0.0){
                                    m_trainPipePressure -= m_trainPipePressureAcceleration_2;

                                    m_totalWindCylinderPressure -= m_trainPipePressureAcceleration_2/60.0;
                                }else{
                                    m_trainPipePressure = 0.0;
                                }

                                if(m_equalizeCylinderPressure - m_equalizeCylinderPressureAcceleration_2 > 0.0){
                                    m_equalizeCylinderPressure -= m_equalizeCylinderPressureAcceleration_2;

                                    m_totalWindCylinderPressure -= m_equalizeCylinderPressureAcceleration_2/60.0;
                                }else{
                                    m_equalizeCylinderPressure = 0.0;
                                }

                                if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_3 < 360.0){

                                    m_brakeCylinderPressure += m_brakeCylinderPressureAcceleration_3;

                                    m_totalWindCylinderPressure -= m_brakeCylinderPressureAcceleration_3/160.0;

                                    m_bigGateBrakeCylinderPressure += m_brakeCylinderPressureAcceleration_3;

                                    m_bigGateBrakeCylinderPressureSaveChangeValue = m_bigGateBrakeCylinderPressure;
                                }else{
                                    if(g_brakeCylinderPressure != m_maxBrakeCylinderPressure){
                                        m_bigGateBrakeCylinderPressure += (m_maxBrakeCylinderPressure - m_brakeCylinderPressure);

                                    }

                                    m_brakeCylinderPressure = m_maxBrakeCylinderPressure;

                                    m_bigGateBrakeCylinderPressureSaveChangeValue = m_bigGateBrakeCylinderPressure;
                                }

                                if(m_brakeCylinderPressure > m_totalWindCylinderPressure){
                                    m_brakeCylinderPressure = m_totalWindCylinderPressure;
                                }else{

                                }

                                m_maxBrakeCylinderPressureSaveMax = m_brakeCylinderPressure;

                                qDebug()<<"大闸制动";
                                qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                                qDebug()<<"m_bigGateBrakeCylinderPressure:"<< m_bigGateBrakeCylinderPressure;
                                qDebug()<<"m_bigGateBrakeCylinderPressureSaveChangeValue:"<<m_bigGateBrakeCylinderPressureSaveChangeValue;
                                qDebug()<<"m_maxBrakeCylinderPressureSaveMax:"<<m_maxBrakeCylinderPressureSaveMax;


                            }


                            //小闸【制动】
                            if(g_smallGateType == BigSmallGate::RetarderLocationType
                                && g_bigGateType != BigSmallGate::RetarderLocationType){
                                if(m_brakeCylinderPressure + m_brakeCylinderPressureAcceleration_10  < 360.0){
                                    m_brakeCylinderPressure += m_brakeCylinderPressureAcceleration_10;

                                    m_totalWindCylinderPressure -= m_brakeCylinderPressureAcceleration_10/30;

                                    m_smallGateBrakeCylinderPressure += m_brakeCylinderPressureAcceleration_10;

                                }else{
                                    if(g_brakeCylinderPressure != m_maxBrakeCylinderPressure){
                                        m_smallGateBrakeCylinderPressure += (m_maxBrakeCylinderPressure - m_brakeCylinderPressure);
                                    }

                                    m_brakeCylinderPressure = m_maxBrakeCylinderPressure;
                                }

                                if(m_brakeCylinderPressure > m_totalWindCylinderPressure){
                                    m_brakeCylinderPressure = m_totalWindCylinderPressure;

                                    m_smallGateBrakeCylinderPressure -= (m_smallGateBrakeCylinderPressure - m_totalWindCylinderPressure);
                                }

                                m_maxBrakeCylinderPressureSaveMax = m_brakeCylinderPressure;

                                qDebug()<<"小闸制动：";
                                qDebug()<<"m_brakeCylinderPressure:"<<m_brakeCylinderPressure;
                                qDebug()<<"m_smallGateBrakeCylinderPressure:"<<m_smallGateBrakeCylinderPressure;

                                qDebug()<<"m_maxBrakeCylinderPressureSaveMax:"<<m_maxBrakeCylinderPressureSaveMax;
                            }

                        }

                    }
                }

                //向下取整
                g_brakeCylinderPressure = round(m_brakeCylinderPressure);
                g_equalizeCylinderPressure = round(m_equalizeCylinderPressure);
                g_trainPipePressure = round(m_trainPipePressure);


                if(m_totalWindCylinderPressure < 0.0){
                    m_totalWindCylinderPressure = 0.0;
                }
                g_totalWindCylinderPressure = floor(m_totalWindCylinderPressure);

                //总风降到660以下，将会自动冲压
                if(m_totalWindCylinderPressure < 660.0){
                    m_isImpulsetotalWindCylinderPressure = true;
                }

                //刷新界面
                emit refreshShow();
            });

}

void CalculateLowerComputerData::stopCalculateWork()
{
    m_timer->stop();
}

void CalculateLowerComputerData::startCalculateWork()
{

    m_timer->start(m_refreshTime);//每20ms刷新一次
}


